package com.lzh.demo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @author liuzhihao
 * @create 2022-01-19 23:14
 */
public class demo4 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String no = scanner.nextLine();

        List<Integer> oneN = new ArrayList();
        List<Integer> twoY = new ArrayList();

        String[] s = no.split(" ");
        for (int i=0; i < s.length; i++) {
            if (s[i].contains("N")) {
                String s1 = s[i].replace("/N", "");
                oneN.add(Integer.parseInt(s1));
            }
            if (s[i].contains("Y")) {
                String s1 = s[i].replace("/Y", "");
                twoY.add(Integer.parseInt(s1));
            }
        }

        Collections.sort(oneN);
        Collections.sort(twoY);

        if (oneN.get(0) > twoY.get(0)) {
            print(twoY);
            print(oneN);
        } else {
            print(oneN);
            print(twoY);
        }

    }
    public static void print(List<Integer> list) {
        for (Integer temp : list) {
            System.out.print(temp+ " ");
        }
        System.out.println();
    }
}
